<template>
  <div class="icons">
    <swiper :options="swiperOptions" class="swiper">
      <swiper-slide class="swiper-slide" v-for="(item, index) in page" :key="index">
        <div class="icon" v-for="i in item" :key="i.id">
          <img class="icon-img" :src="i.imgUrl" alt="">
          <p>{{ i.desc }}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  props: {
    iconsList: Array
  },
  data () {
    return {
      swiperOptions: {
        pagination: '.swiper-pagination',
        observeParents: true,
        observer: true
      }
    }
  },
  computed: {
    page () {
      const pages = []
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
  .icons >>> .swiper-pagination-bullet-active
    background red !important
  .icons
    overflow hidden
    height 0
    padding-bottom 44%
    .swiper-slide
      display flex
      justify-content space-between
      flex-wrap wrap
    .icon
      width 25%
      height 0
      display flex
      flex-direction column
      justify-content space-between
      align-items center
      font-size 0.24rem
      padding-bottom 21%
      .icon-img
        width 50%
        text-index .2rem
</style>
